//
//  MineCell.m
//  CarLife
//
//  Created by yu on 2019/6/3.
//  Copyright © 2019年 jpas. All rights reserved.
//

#import "MineCell.h"

@implementation MineCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.lineView = [[UIView alloc] init];
    self.lineView.backgroundColor = kLineFrameGrayColor;
    [self.contentView addSubview:self.lineView];
   
    self.lineView.sd_layout
    .leftSpaceToView(self.contentView, 17)
    .bottomSpaceToView(self.contentView, 0)
    .rightSpaceToView(self.contentView, 0)
    .heightIs(0.5);
}

- (IBAction)handleAction:(UITapGestureRecognizer *)sender {
    if (self.handleBlock) {
        self.handleBlock(sender.view.tag);
    }
}

+ (instancetype)initTableViewCellWith:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    NSString *identifier;
    NSInteger index = 0;
    switch (indexPath.section) {
        case 0:
            switch (indexPath.row) {
                case 0:
                    identifier = @"MineCell0";
                    index = 0;
                    break;
                case 1:
                    identifier = @"MineCell1";
                    index = 1;
                default:
                    break;
            }
            break;
        case 1:
            identifier = @"MineCell2";
            index = 2;
            break;
        case 2:
            identifier = @"MineCell2";
            index = 2;
            break;
        default:
            break;
    }
    
    NSArray *titlesArray = @[@[@"",@""],@[@"我的收藏",@"我的点赞"],@[@"帮助与反馈",@"设置"]];
    NSArray *imgsArray = @[@[@"",@""],@[@"mine_collection",@"mine_like"],@[@"mine_feedback",@"mine_setting"]];
    
    MineCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MineCell" owner:self options:nil] objectAtIndex:index];
    }
    cell.imgView.image = IMAGE_NAMED(NSStringFormat(@"%@",imgsArray[indexPath.section][indexPath.row]));
    cell.titleLabel.text = titlesArray[indexPath.section][indexPath.row];
    
    if (indexPath.row % 2 != 0) {
        cell.lineView.hidden = YES;
    }
    if (!indexPath.section && !indexPath.row) {
        cell.lineView.sd_resetLayout
        .leftSpaceToView(cell.contentView, 0)
        .bottomSpaceToView(cell.contentView, 0)
        .rightSpaceToView(cell.contentView, 0)
        .heightIs(0.5);
    }
    
    return cell;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
